
<template>

  <div class="login-wrapper">
    <div class="modal">
      <el-form ref="userForm" :model="user" status-icon :rules="rules">
        <div class="title">即时通讯管理后台</div>
        <el-form-item prop="username"> 
          <el-input type="text" prefix-icon="user" v-model="user.username"/>
        </el-form-item>
        
        <el-form-item prop="password">
          <el-input type="password" prefix-icon="view" v-model="user.password" @keyup.enter.native="login"/>
        </el-form-item>

        <el-form-item>
          <el-button class="btn-login" type="primary" @click="login">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script >
import { ElButton } from "element-plus"
import * as ELIcons from '@element-plus/icons-vue'

import conf from '../config'
import axios from 'axios'
// import { tr } from 'element-plus/es/locale'
export default {
  name: "登录页面",
  components: { 
    ElButton,
   },
   

  data(){
    return{
      user:{
        username:'',
        password:'',
      },
      rules:{
        username:[
          {
            required:true,message:"请输入用户名", trigger:'blur'
          }
        ],
        password:[
          {
            required:true,message:"请输入密码", trigger:'blur'
          }
        ]
      }
    }
  },
  mounted() {
    // axios.get(conf.mockApi + "/login").then((res) => {
    //   console.log(res);
    // });

    // this.$request({
    //   method :'get',
    //   url:'/login',
    // }).then((res)=>{
    //   console.log(res)
    // })

    // this.$request.get('/login',{name:'lee'},{mock:true,loading:true}).then(
    //   (res)=>{
    //     console.log(res)
    //   }
    // )
  },
  methods: {
    goHome() {
      this.$router.push("/welcome");
    },

    login(){
        this.$refs.userForm.validate((valid)=>{
            if(valid){//登录成功的话
              this.$apis.login(this.user).then((res)=>{
                
                console.log(res);
                this.$store.commit('saveUserInfo',res)
                this.$router.push('/welcome');
              })
            }else{
              return false;
            }
        })

    },
    


  },


};
</script>

<style lang="scss">
.login-wrapper{
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f9fcff;
  widows: 100vw;
  height: 100vh;
  .modal{
    width: 500px;
    padding: 50px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0px 0px 10px 3px #c7c9cd;
    .title{
      font-size: 50px;
      line-height: 1.5;
      text-align: center;
      margin-bottom: 30px;
      .userClass{
          background-color: #000;
      }
    }
    .btn-login{
      width: 100%;
    }
  }
}
</style>
